// Date: 2007.12.13 15:45 rd

int main()
{
	print("<h2>Neutron activation of Bi-209 for Po-210 production</h2>");

	double mass = 35e-9;			// considere a mass of 35 ng
	double f = 1;			// of 100% pure Bi209 implanted in a metal matrix

	double phi_th = 1E13;			// thermal neutrons flux  [/cm2/s]
	double phi_epi = 2E7;			// epithermal neutron flux  [/cm2/s]
	double Teff = 300;			// effectif Temperature of the thermal neutron flux [K]

	string XSLibrary[5] = {"JEF 2.2", "BROND 2", "ENDF/B VI", "JENDL 3.2", "CENDL 2"};
	int xsLib=0;				// Library: the JEF 2.2 values (worst case) are given with xsLib=0
	double pi = 3.14159;

	nuclide target;				// the target nuclide which will be activated by neutron irradiation
	target.Create("Bi", 209, 0);
	crossSections xstarget;
	xstarget = target.CrossSections(xsLib);	// Bi209 CrossSections from the BROND 2 library (worst case)
	double rho;  rho = target.AB/100;	// natural abundance of the Bi209 isotope

	print("Considere a " + mass/1E3 + " kg probe containing a mass fraction of " + f*100 + " % " + target.IsotopeScreenFormat);
	print("The natural abundance &rho; in Nucleonica is " + rho*100+ " %");
	print("This probe will be activated in a nuclear reactor through a flux");
	print("     of " + format(phi_th, "0.000E+00") + " thermal neutrons/cm<sup>2</sup>/s at " + Teff + " K and");
	print("     of " + format(phi_epi, "0.000E+00") + " epithermal neutrons/cm<sup>2</sup>/s (which can be neglected).");
 
	int r; int ng=-1;
	print("<table>");
	print("<caption>Excerpt from Neutron crosssection of " + XSLibrary[xsLib] + "</caption>");
	print("<thead><th>Nr</th><th>Reaction</th><th>Thermal</th><th>Epithermal</th></thead>");
	print("<body>");
	for(r=0; r<xstarget.Count; r=r+1)
	{
		print("<tr><td>"+ r + "</td><td>" + xstarget.Reaction(r) + "</td><td>" + xstarget.m_per_s_2200(r) + "</td><td>" + xstarget.Res_Integral(r) + "</td></tr>");
		if (xstarget.Reaction(r) == "n,g") ng=r;
	}
	print("</tbody>");
	print("</table>");
	
	if (ng<0) print("Reaction not found");

	double sigma_th;			// n-gamma CrossSection for thermal neutrons from selected Library
	double sigma_epi;			// n-gamma CrossSection for epithermal neutrons
	double J;				// Reaction Rate
	sigma_th = xstarget.m_per_s_2200(ng);	// n-gamma CrossSection for thermal-neutrons (2200m/s)
	sigma_epi = xstarget.Res_Integral(ng);	// n-gamma CrossSection for epithermal-neutrons (resonance integral)

	print("The total reaction rate is given by:");
	print("J = &phi;<sub>th</sub> * sqrt(293.6/T<sub>eff</sub>) * sqrt(&pi;) / 2 * &sigma;<sub>th</sub> * 1E-24 + &phi;<sub>epi</sub> * &sigma;<sub>epi</sub> * 1E-24");
	J = phi_th * sqrt(293.6/Teff) * sqrt(pi) / 2 * sigma_th * 1E-24 + phi_epi * sigma_epi * 1E-24;
	print("(J is approx. &sigma; * &phi;)");

	print(" ");
	print("The Cross Sections found in the " + XSLibrary[xsLib] + " library are:");
	print("     &sigma;<sub>th</sub> = " + sigma_th + " barns");
	print("     &sigma;<sub>epi</sub> = " + sigma_epi + " barns");
	print("which gives a rate  J = " + format(J, "0.000E+00") + " reactions/sec");
	print("From the total produced Bi210, only 2/3 are in the ground state:");
	J = J*2/3;
	print("   J<sub>Bi210g</sub> = " + format(J, "0.000E+00") + " reactions/sec");

	double Asat;		// the activity at saturation
	print(" ");
	print("The saturation activity given by:");
	print("A<sub>sat</sub> = mass * f * &rho; * J * Const_Avogadro / target.AWR_C12");
	Asat = mass * f * rho * J * Const_Avogadro / target.AWR_C12;
	print("is then:");
	print("A<sub>sat</sub> = " + format(Asat, "0.000E+00") + " Bq");

	nuclide nap;				// the activation product nuclide
	nap.Create(target.Z, target.A+1, 0);
	nuclide ndp1;				// the first decay product nuclide 
	decayResult dknap;			// lets decay the activation product to
	dknap = nap.Decay(Asat, "bq", 1, "s",  1, 1, 1E-2, "halflife,branching,decay,numbers,mass,activity,activitya,activityb,emission,dose,fission,ingestion,inhalation,isopow,isopowa,isopowb");
	ndp1 = dknap.Nuclide(1);		// get the first decay product from the decayResult of the activation product (this is more general)

	int d; int db=0; int de=365; int ds=5;
	double t;				// ellapsed time in seconds
	double kPo; kPo = log(2)/ndp1.Halflife;	// Po210 decay constant
	double kBi; kBi = log(2)/nap.Halflife;	// Bi210 decay constant
	double ABi210; double mBi210;		// Bi210 activity and mass at time t
	double APo210; double mPo210;		// Po210 activity  and mass at time t

	print("<table>");
	print("<caption>Po-210 production after " + format(db, "0") + " to " + format(de, "0") + " days irradiation</caption>");
	print("<thead>");
	print("<tr><th>Time[d]</th><th>Activity[Bq]</th><th>Mass[g]</th><th>Activity[Bq]</th><th>Mass[g]</th></tr>");
	print("</thead>");
	print("<tbody>");
	for(d=db; d<=de; d=d+ds)		// Po-210 production
	{
		if (d==0) d=1;
		if (d==6) d=5;
		t = 86400*d;				// ellapsed time in seconds
		ABi210 = Asat * (1 - exp(- kBi*t));	// Activity of Bi210
		mBi210 = ABi210 / kBi * nap.AWR_C12 / Const_Avogadro;
		APo210= Asat / (kBi-kPo) * (kBi*(1-exp(- kPo*t)) - kPo*(1-exp(- kBi*t)));
		mPo210 = APo210 / kPo * ndp1.AWR_C12 / Const_Avogadro;
		print("<tr><td>"+d+"</td><td>"+format(ABi210,"0.000E+00")+"</td><td>"+format(mBi210, "0.000E+00")+"</td><td>"+format(APo210,"0.000E+00")+"</td><td>"+format(mPo210, "0.000E+00")+"</td></tr>");
	}
	print("</tbody>");
	print("</table>");

	print("d,Bi210,Po210");
	for(d=db; d<=de; d=d+ds)		// Po-210 production
	{
		if (d==0) d=1;
		if (d==6) d=5;
		t = 86400*d;				// ellapsed time in seconds
		ABi210 = Asat * (1 - exp(- kBi*t));		// Activity of Bi210
		mBi210 = ABi210 / kBi * nap.AWR_C12 / Const_Avogadro;
		APo210= Asat / (kBi-kPo) * (kBi*(1-exp(- kPo*t)) - kPo*(1-exp(- kBi*t)));
		mPo210 = APo210 / kPo * ndp1.AWR_C12 / Const_Avogadro;
		print(" "+d+", "+format(ABi210, "0.0000E+00")+", "+format(APo210, "0.0000E+00"));
	}
}